package com.ll.method;

/**
 * @author 刘龙
 * @version 1.0
 */
public class ThreadMethod02 {
    public static void main(String[] args) throws InterruptedException {
        T2 t2 = new T2();
        t2.start();

        for (int i = 0; i < 20; i++) {
            System.out.println(Thread.currentThread().getName() + "吃包子..." + i);
            if (i == 5) {
                System.out.println("让子线程先吃");
                // 线程插队
                t2.join();

                // 礼让,不一定成功,资源紧张成功率高
               // Thread.yield();
                System.out.println("子线程已经吃完了,到主线程吃了");

            }
            Thread.sleep(1000);

        }
    }
}

class T2 extends Thread {
    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "吃包子..." + i);
        }
    }
}


